using System;
using System.Collections.Generic;
using System.Windows;
using System.Windows.Input;
using HelloWindowsPhoneMVC.Controllers;
using HelloWindowsPhoneMVC.Model;
using Microsoft.Phone.Shell;
using WindowsPhoneEssentials.Commands;
using WindowsPhoneMVC;
using WindowsPhoneMVC.Navigation;

namespace HelloWindowsPhoneMVC.ViewModels.Home
{
    public class MainViewModel : ViewModelBase
    {
        private string name;

        public MainViewModel()
        {
            //There are plenty of ways to navigate, pick the one that you like
            ShowGreetingPageCommand = Controller<HomeController>().InvokeCommand(c => c.SayHelloTo(Name));
            ShowAnotherExamplePageCommand = Controller<AnotherController>().InvokeCommand(c => c.Example());
            ShowAboutDialogCommand = new DelegateCommand(() => Controller<HomeController>().Invoke(c => c.AboutDialog(null)));
            CreateDeepLinkCommand = new DelegateCommand(CreateDeepLink);
            DebugPageCommand = new DelegateCommand(() => Navigator.Invoke("Home", "DebugPage"));
            SaveCommand = new DelegateCommand(Save, () => false);

            Transient(() => Name);
        }

        private void CreateDeepLink()
        {
            var deepLinkUri = Controller<HomeController>().UriFor(c => c.DeepLinkPage, new Dictionary<string, string>());
            ShellTile.Create(new Uri(deepLinkUri, UriKind.Relative), new StandardTileData
                                                        {
                                                            BackgroundImage = new Uri("/ApplicationIcon.png", UriKind.Relative),
                                                            Title = "MVC Deep Link"
                                                        });
        }

        public void Save()
        {
            MessageBox.Show("Save Clicked");
        }

        public string Name
        {
            get { return name; }
            set
            {
                name = value;
                OnPropertyChanged(() => Name);
            }
        }

        public ICommand SaveCommand { get; set; }

        public ICommand DebugPageCommand { get; set; }

        public ICommand ShowAboutDialogCommand { get; set; }

        public ICommand ShowGreetingPageCommand { get; set; }

        public ICommand CreateDeepLinkCommand { get; set; }

        public ICommand ShowAnotherExamplePageCommand { get; private set; }

        public ItemFromList SomeItem
        {
            get { return new ItemFromList(); }
        }
    }
}